<html>
<head><meta charset="utf-8"><title>Using traits to eliminate boilerplate · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html">Using traits to eliminate boilerplate</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="242012031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012031">(Jun 09 2021 at 02:39)</a>:</h4>
<p>So in my latest draft on <code>feat/gather</code>, I drafted a SimdArray trait that allows us to basically define everything in our implementation that is primitive-neutral in terms of that implementation. I  don't think we should overuse traits, but I think that we have an opportunity to simplify our code significantly using this, and move more things out of macros.</p>
<p>However, I also noticed something else while experimenting with trait bounds. It would require a significant amount of reworking of our code, because it requires refactoring our codebase, but: We may be able to significantly limit the amount of frankly onerous trait bounds in our code if we simplify the traits to gating only <strong>the construction of the types</strong>.</p>



<a name="242012107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012107">(Jun 09 2021 at 02:41)</a>:</h4>
<p>I don't think that's possible, you can always construct the type via transmuting it</p>



<a name="242012181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012181">(Jun 09 2021 at 02:43)</a>:</h4>
<p>Also you could always compile a function that takes it as an argument even if you don't construct it, and that codegen would obviously fail</p>



<a name="242012430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012430">(Jun 09 2021 at 02:49)</a>:</h4>
<p>Damn.</p>



<a name="242012451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012451">(Jun 09 2021 at 02:50)</a>:</h4>
<p><del>I mean I'm not terribly concerned about the last one, even if it's suboptimal.</del></p>



<a name="242012504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012504">(Jun 09 2021 at 02:50)</a>:</h4>
<p>Well it's more that you'd get bad compiler errors</p>



<a name="242012509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012509">(Jun 09 2021 at 02:51)</a>:</h4>
<p>Or you could write out a bunch of code that compiled and then get frustrated when you can't actually use it</p>



<a name="242012524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012524">(Jun 09 2021 at 02:51)</a>:</h4>
<p>Right.</p>



<a name="242012595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012595">(Jun 09 2021 at 02:53)</a>:</h4>
<p>Also wrt your first point, I think I don't like the idea of using traits in a public interface to avoid macros in a private implementation. A trait could totally be appropriate here but I think it needs to be appropriate for the API and implementation is secondary</p>



<a name="242012837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012837">(Jun 09 2021 at 02:58)</a>:</h4>
<p>Mostly, I think it's useful because it allows us to provide a guarantee that an interface is replicated across all the relevant types, and which parts.</p>



<a name="242012939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012939">(Jun 09 2021 at 03:00)</a>:</h4>
<p>Yeah that's a potential benefit (though I would argue macros do the same thing)</p>



<a name="242012953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242012953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242012953">(Jun 09 2021 at 03:01)</a>:</h4>
<p>Note I haven't actually looked at the branch at all yet so this is more just general sentiment and not about this particular implementation</p>



<a name="242013006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013006">(Jun 09 2021 at 03:02)</a>:</h4>
<p>I'm guessing it probably makes sense here for the same reason <code>Select</code> is a trait</p>



<a name="242013008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013008">(Jun 09 2021 at 03:02)</a>:</h4>
<p>Yeah I still have to rework a bunch of stuff anyways unfortunately. ^^;<br>
But having paid some time to attend to <code>std</code>, I don't want to criticize it a bunch but there's been a lot of cases where <code>std</code>, in spite of having hundreds of readers a day, and in spite of lots of macro work, has had very uneven application of things across types. ^^;</p>



<a name="242013036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013036">(Jun 09 2021 at 03:03)</a>:</h4>
<p>Yeah definitely. I do think there is a greater cognitive load with traits, though, since you need to understand the trait itself, and then the implementations (which can be complicated...)</p>



<a name="242013084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013084">(Jun 09 2021 at 03:04)</a>:</h4>
<p>Yeah. :/<br>
Here, I hope we can offer an exceedingly uniform interface and try to not overload it, at least.</p>



<a name="242013089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013089">(Jun 09 2021 at 03:04)</a>:</h4>
<p>Agreed</p>



<a name="242013115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013115">(Jun 09 2021 at 03:05)</a>:</h4>
<p>Tangentially related I actually think we should look at reworking shuffles to make the interface a little more intuitive</p>



<a name="242013119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013119">(Jun 09 2021 at 03:05)</a>:</h4>
<p>Oh?</p>



<a name="242013211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013211">(Jun 09 2021 at 03:07)</a>:</h4>
<p>I think there are a few things we can look at</p>



<a name="242013228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013228">(Jun 09 2021 at 03:07)</a>:</h4>
<p>I think we can consider using const panics instead of the whole confusing modulo thing</p>



<a name="242013291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013291">(Jun 09 2021 at 03:08)</a>:</h4>
<p>But more along the lines of the traits thing, it would be nice if we could do <code>indices.shuffle(a, b)</code> like we can do with select</p>



<a name="242013295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013295">(Jun 09 2021 at 03:08)</a>:</h4>
<p>Obviously we can't</p>



<a name="242013313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013313">(Jun 09 2021 at 03:09)</a>:</h4>
<p>But perhaps there's something we can do to make that interface a little less confusing</p>



<a name="242013317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013317">(Jun 09 2021 at 03:09)</a>:</h4>
<p>I am pretty sure we don't do the modulo thing tho'.</p>



<a name="242013320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013320">(Jun 09 2021 at 03:09)</a>:</h4>
<p>Hmm</p>



<a name="242013326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013326">(Jun 09 2021 at 03:09)</a>:</h4>
<p>Well I don't think we panic</p>



<a name="242013372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013372">(Jun 09 2021 at 03:10)</a>:</h4>
<p>I think simd_shuffle fails to compile. ^^;</p>



<a name="242013376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013376">(Jun 09 2021 at 03:10)</a>:</h4>
<p>if memory serves.</p>



<a name="242013386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013386">(Jun 09 2021 at 03:10)</a>:</h4>
<p>Ah. Perhaps even worse</p>



<a name="242013400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013400">(Jun 09 2021 at 03:10)</a>:</h4>
<p>well a const panic would just be a compile error too.</p>



<a name="242013415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013415">(Jun 09 2021 at 03:11)</a>:</h4>
<p>One with source information <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="242013418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013418">(Jun 09 2021 at 03:11)</a>:</h4>
<p>...true!</p>



<a name="242013427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013427">(Jun 09 2021 at 03:11)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/76768/files">https://github.com/rust-lang/rust/pull/76768/files</a><br>
Ah yes, I added the test to verify that we fail to compile.</p>



<a name="242013471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013471">(Jun 09 2021 at 03:12)</a>:</h4>
<blockquote>
<p>error[E0511]: invalid monomorphization of <code>simd_shuffle4</code> intrinsic: shuffle index <a href="https://github.com/rust-lang/rust/issues/0">#0</a> is out of bounds (limit 8)</p>
</blockquote>



<a name="242013477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013477">(Jun 09 2021 at 03:12)</a>:</h4>
<p>That error could certainly be better</p>



<a name="242013480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013480">(Jun 09 2021 at 03:13)</a>:</h4>
<p>Though also better than expected</p>



<a name="242013481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013481">(Jun 09 2021 at 03:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate/near/242013291">said</a>:</p>
<blockquote>
<p>But more along the lines of the traits thing, it would be nice if we could do <code>indices.shuffle(a, b)</code> like we can do with select</p>
</blockquote>
<p>idk actually, I think we could.</p>



<a name="242013550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013550">(Jun 09 2021 at 03:14)</a>:</h4>
<p>I think you could do it with something crazy like <code>struct Indices&lt;const Array: ...&gt;</code></p>



<a name="242013556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013556">(Jun 09 2021 at 03:14)</a>:</h4>
<p>yah basically.</p>



<a name="242013583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013583">(Jun 09 2021 at 03:15)</a>:</h4>
<p>And perhaps a shuffle trait which would map array types to appropriate vector types</p>



<a name="242013588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013588">(Jun 09 2021 at 03:15)</a>:</h4>
<p>Much like select</p>



<a name="242013602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013602">(Jun 09 2021 at 03:16)</a>:</h4>
<p>Oh?</p>



<a name="242013631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013631">(Jun 09 2021 at 03:16)</a>:</h4>
<p>Well maybe <code>Swizzle</code> considering the other conversation</p>



<a name="242013648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013648">(Jun 09 2021 at 03:16)</a>:</h4>
<p>well something like</p>



<a name="242013765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013765">(Jun 09 2021 at 03:19)</a>:</h4>
<div class="codehilite"><pre><span></span><code>trait Swizzle {
   type Indices;
}

...
    fn swizzle&lt;T: Swizzle&lt;Self::Indices&gt;&gt;(v: T)
</code></pre></div>



<a name="242013769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013769">(Jun 09 2021 at 03:19)</a>:</h4>
<p>Idk probably too many dependent types there lol</p>



<a name="242013827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013827">(Jun 09 2021 at 03:20)</a>:</h4>
<p>But something so the index type is dependent on the vector type</p>



<a name="242013829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013829">(Jun 09 2021 at 03:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="312331">Caleb Zulawski</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate/near/242013827">said</a>:</p>
<blockquote>
<p>But something so the index type is dependent on the vector type</p>
</blockquote>
<p>hm, why would we vary that?</p>



<a name="242013855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013855">(Jun 09 2021 at 03:21)</a>:</h4>
<p>For a similar reason as why masks can select multiple vector types</p>



<a name="242013899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013899">(Jun 09 2021 at 03:22)</a>:</h4>
<p>There's no reason for them to be different types</p>



<a name="242013903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242013903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242013903">(Jun 09 2021 at 03:22)</a>:</h4>
<p>That's about it</p>



<a name="242014000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242014000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242014000">(Jun 09 2021 at 03:24)</a>:</h4>
<p>Mm!</p>



<a name="242014128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242014128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242014128">(Jun 09 2021 at 03:27)</a>:</h4>
<p>That's definitely why I bothered with the trait tho':</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">gather</span><span class="p">(</span><span class="n">slice</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="bp">Self</span>::<span class="n">Scalar</span><span class="p">],</span><span class="w"> </span><span class="n">idxs</span>: <span class="nc">SimdUsize</span><span class="o">&lt;</span><span class="n">LANES</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"></span>
</code></pre></div>



<a name="242014195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242014195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242014195">(Jun 09 2021 at 03:28)</a>:</h4>
<p>( there is no particular reason for the SimdUsize as the indicing, It Just Happened To Be There. )</p>



<a name="242014419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242014419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242014419">(Jun 09 2021 at 03:33)</a>:</h4>
<p>Yep definitely makes sense to me</p>



<a name="242018209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242018209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242018209">(Jun 09 2021 at 04:59)</a>:</h4>
<p>...it's too bad we don't have IndexGet.<br>
Then swizzle could just be indicing with an array.</p>



<a name="242018277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242018277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242018277">(Jun 09 2021 at 05:00)</a>:</h4>
<p>feel like my brain expanded 10 sizes just figuring that out.</p>



<a name="242019908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242019908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242019908">(Jun 09 2021 at 05:37)</a>:</h4>
<p>using traits has two main effects on the library user: it allows generics, but it also makes docs worse.</p>



<a name="242020948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242020948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242020948">(Jun 09 2021 at 05:59)</a>:</h4>
<p>Hmm, I wonder if &lt;<a href="https://github.com/rust-lang/rfcs/pull/2375">https://github.com/rust-lang/rfcs/pull/2375</a>&gt; could help with that.</p>
<p>Makes me wonder if a <em>private</em> trait can still be <code>#[inherent]</code>...</p>



<a name="242051603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242051603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242051603">(Jun 09 2021 at 11:40)</a>:</h4>
<p>There is also the issue that they need to be imported</p>



<a name="242082647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242082647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242082647">(Jun 09 2021 at 15:21)</a>:</h4>
<p>That's what inherent is supposed to solve (some day far from now).</p>



<a name="242082737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242082737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242082737">(Jun 09 2021 at 15:21)</a>:</h4>
<p>I read that as "inherit" earlier and totally misunderstood</p>



<a name="242083292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Using%20traits%20to%20eliminate%20boilerplate/near/242083292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Using.20traits.20to.20eliminate.20boilerplate.html#242083292">(Jun 09 2021 at 15:25)</a>:</h4>
<p>As to what Scott said: if inherent trait methods get grouped with normal methods in rustdoc output (which seems possible?) then it would eliminate the docs issue.</p>
<p>As is, trait impl methods on a type are treated as second class within the docs and so trait impl oriented types don't read well at all.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>